package com.promise.jokerdream.response.pc

import kotlinx.serialization.Serializable
import kotlinx.serialization.SerialName

@Serializable
data class QueryWeaponSpecializeResponse(
    override val result: Int,
    override val msg: String = "",
    // 武器类型ID
    @SerialName("weapon_type_id")
    val weaponTypeId: String = "",
    // 等级
    val level: String = "",
    // 名称
    val name: String = "",
    // 升级物品ID
    @SerialName("update_goods_id")
    val updateGoodsId: String = "",
    // 升级所需数量
    @SerialName("update_goods_needs")
    val updateGoodsNeeds: String = "",
    // 祝福值
    val bless: String = "",
    // 祝福上限
    @SerialName("bless_limit")
    val blessLimit: String = "",
    // 存储槽列表
    val storages: List<WeaponStorage> = emptyList(),
): BasePCResponse {
    override fun getDescription(): String {
        return msg
    }
    
    /**
     * 根据武器类型ID返回类型名称
     * 0为投掷、1为小型、2为中型、3为大型
     */
    fun getWeaponTypeName(): String {
        return when (weaponTypeId.toIntOrNull()) {
            0 -> "投掷"
            1 -> "小型"
            2 -> "中型"
            3 -> "大型"
            else -> "未知"
        }
    }
    
    /**
     * 解析名称中的阶数并格式化显示
     * name格式为"n阶xx"，解析出中文数字n，返回"n-level"
     */
    fun getFormattedLevel(): String {
        // 解析中文数字
        val chineseNumbers = mapOf(
            "一" to 1, "二" to 2, "三" to 3, "四" to 4, "五" to 5,
            "六" to 6, "七" to 7, "八" to 8, "九" to 9, "十" to 10
        )
        
        // 从name中提取阶数（格式：n阶xx）
        val regex = Regex("([一二三四五六七八九十]+)阶")
        val match = regex.find(name)
        
        val orderNumber = if (match != null) {
            val chineseNum = match.groupValues[1]
            chineseNumbers[chineseNum] ?: 0
        } else {
            // 如果没有匹配到，尝试直接解析数字
            name.replace(Regex("[^0-9]"), "").toIntOrNull() ?: 0
        }
        
        return "$orderNumber-$level"
    }
}

@Serializable
data class WeaponStorage(
    // 存储槽等级
    @SerialName("storage_level")
    val storageLevel: String = "",
    // 武器ID
    @SerialName("weapon_id")
    val weaponId: String = "",
    // 武器名称
    @SerialName("weapon_name")
    val weaponName: String = "",
)
